package com.example.service;

import com.example.dao.AnswerDao;
import com.example.model.pojo.Answer;
import com.example.model.pojo.Discussion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 27954
 * @Description TODO
 * @Date 2022/9/18 19:47
 */
@Transactional
@Service
public class AnswerService implements IAnswerService{
    @Autowired
    private AnswerDao answerDao;

    @Override
    public Page<Answer> loadHotAnswerService(Integer pageNum, Integer pageSize) {
        Sort sort=Sort.by(new Sort.Order(Sort.Direction.DESC,"likeNum"),new Sort.Order(Sort.Direction.DESC,"viewNum"));
        Pageable pageable= PageRequest.of(pageNum,pageSize,sort);
        Page<Answer> page= answerDao.findAll(pageable);
        return page;
    }
}
